home *** CD-ROM | disk | FTP | other *** search
- /* sorttext.c - sort a text file ( lines of ASCII characters) */
- #include "stdio.h"
- #include "cminor.h"
- #include "sorttext.h"
-
- int strcmp() ; /* string compare function */
- FILE *do_open() ; /* opens file and checks for errors */
-
- main(argc,argv)
- int argc ; /* number of words in command ine */
- char *argv[] ; /* pointers to each word */
- {
- /* check to see that file names were specified */
- if( argc < 3 )
- { printf(" need file names \n") ;
- printf(" USAGE: sortfile input-file output-file \n") ;
- exit(1) ;
- }
-
- dosort(argv[1],argv[2]) ; /* do the sort */
- }
-
-
- int dosort(fromfile,tofile)
- char fromfile[] ; /* input for sort */
- char tofile[] ; /* put the output here */
- {
- int nrec ;
- char sarea[ SSIZE ] ; /* storage area for text lines */
- char *p[ MAX_REC ] ; /* pointers to lines of text */
- FILE *infile ; /* input file */
-
- infile = do_open(fromfile,"r") ; /* open input file */
- initfill(infile) ; /* initialize for fillarea */
- /* read text file in storage area */
- if( fillarea(sarea,SSIZE,p,MAX_REC,&nrec,infile) != AT_EOF)
- { printf("file too large") ;
- exit(3) ;
- }
- do_close(infile,fromfile) ;
-
- memsort(p,nrec,strcmp) ; /* sort using string compare fun. */
- outfile(p,nrec,tofile) ; /* write sorted lines out */
- }
-
-
-